package com.hongxun.project.assets.pPullLine.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.pPullLine.mapper.PPullLineMapper;
import com.hongxun.project.assets.pPullLine.domain.PPullLine;
import com.hongxun.project.assets.pPullLine.service.IPPullLineService;
import com.hongxun.common.utils.text.Convert;

/**
 * 拉线采集 服务层实现
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class PPullLineServiceImpl implements IPPullLineService {
    @Autowired
    private PPullLineMapper pPullLineMapper;

    /**
     * 查询拉线采集信息
     *
     * @param id 拉线采集ID
     * @return 拉线采集信息
     */
    @Override
    public PPullLine selectPPullLineById(String id, String taskId) {
        return pPullLineMapper.selectPPullLineById(id, taskId);
    }

    @Override
    public PPullLine selectPPullLineByIdForState(String id, String taskId) {
        return pPullLineMapper.selectPPullLineByIdForState(id, taskId);
    }

    /**
     * 查询拉线采集列表
     *
     * @param pPullLine 拉线采集信息
     * @return 拉线采集集合
     */
    @Override
    public List<PPullLine> selectPPullLineList(PPullLine pPullLine) {
        return pPullLineMapper.selectPPullLineList(pPullLine);
    }

    /**
     * 新增拉线采集
     *
     * @param pPullLine 拉线采集信息
     * @return 结果
     */
    @Override
    public int insertPPullLine(PPullLine pPullLine) {
        pPullLine.setId(UUID.randomUUID().toString());
        return pPullLineMapper.insertPPullLine(pPullLine);
    }

    /**
     * 修改拉线采集
     *
     * @param pPullLine 拉线采集信息
     * @return 结果
     */
    @Override
    public int updatePPullLine(PPullLine pPullLine) {
        return pPullLineMapper.updatePPullLine(pPullLine);
    }

    /**
     * 删除拉线采集对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePPullLineByIds(String ids) {
        return pPullLineMapper.deletePPullLineByIds(Convert.toStrArray(ids));
    }


    @Override
    public int deletePPullLineByIdsAndTaskIds(String ids, String taskIds) {
        return pPullLineMapper.deletePPullLineByIdsAndTaskIds(Convert.toStrArray(ids), Convert.toStrArray(taskIds));
    }

    @Override
    public void insertOrReplaceOrDelete(List<PPullLine> entities) {
        for (PPullLine d : entities) {
//			if (d.getDatastate().equals("删除")) {
//				pPullLineMapper.deletePPullLineByIdsAndTaskIds(Convert.toStrArray(d.getId()) , Convert.toStrArray(d.getTaskId()));
//			} else {
            PPullLine pPullLine = pPullLineMapper.selectPPullLineById(d.getId(), d.getTaskId());
            if (pPullLine == null) {
                pPullLineMapper.insertPPullLine(d);
            } else {
                pPullLineMapper.updatePPullLine(d);
            }
//			}
        }
    }

}
